package com.zksite.nator.server.http.ssl;

import java.io.InputStream;

import javax.net.ssl.SSLException;

import io.netty.handler.ssl.SslContext;
import io.netty.handler.ssl.SslContextBuilder;

public class SslContextFactory {

	private volatile static SslContext context;

	public static SslContext getSslContext() {
		synchronized (SslContextFactory.class) {
			if (context == null) {
				InputStream crt = SslContextFactory.class.getClassLoader().getResourceAsStream("server.crt");
				InputStream key = SslContextFactory.class.getClassLoader().getResourceAsStream("private.pem");
				try {
					context = SslContextBuilder.forServer(crt, key).build();
				} catch (SSLException e) {
					e.printStackTrace();
				}
			}
		}
		return context;
	}
}
